package com.ruleengine.compiler.impl;

import com.ruleengine.compiler.exception.CompilerException;
import com.ruleengine.instruction.InstructionManager;
import com.ruleengine.instruction.InstructionSet;
import com.ruleengine.instruction.InstructionType;
import com.ruleengine.instruction.impl.CallWorkflowInstruction;
import com.ruleengine.task.impl.CallWorkflowTask;


/**
 * @author wuxiao
 *
 * Created on Mar 28, 2012
 */
public class CallWorkflowTaskCompiler extends BaseCompiler<CallWorkflowTask> {

    /* (non-Javadoc)
     * @see com.wx.workflow.engine.compiler.impl.BaseCompiler#comipleSubTask(com.wx.workflow.task.ITask)
     */
    @Override
    public void comipleSubTask(CallWorkflowTask task, InstructionSet instSet) throws CompilerException {
        // TODO Auto-generated method stub
        //callworkflow没有子指令
        CallWorkflowInstruction callIn = InstructionManager.getInstance().createInstruction(InstructionType.CALLWORKFLOW);
        String[] target = task.getTarget().split(":", 2);
        if(target.length==2){
            callIn.setTargetType(target[0]);
            callIn.setTarget(target[1]);
        }else{
            callIn.setTargetType("literal");
            callIn.setTarget(target[0]);
        }
        
        instSet.addInstruction(callIn);
    }


}
